package com.wuzhun.wxmp.service.impl;

import com.wuzhun.wxmp.common.ResultCode;
import com.wuzhun.wxmp.common.ServiceException;
import com.wuzhun.wxmp.service.ICaptchaServiceService;
import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * 验证码服务
 *
 * @author Paulin
 * @date 2023/4/4 13:53
 */
@Service
public class CaptchaServiceImpl implements ICaptchaServiceService {
    @Override
    public void verifyImageCode(HttpServletRequest request, String code, boolean ignoreCase) {
//        boolean verifyCheckStatus = HappyCaptcha.verification(request, code, ignoreCase);
//        if (!verifyCheckStatus) {
//            throw new ServiceException(ResultCode.IMAGE_CODE_WRONG);
//        }
//        HappyCaptcha.remove(request);
        if (!CaptchaUtil.ver(code, request)) {
            // 清除session中的验证码
            CaptchaUtil.clear(request);
            throw new ServiceException(ResultCode.IMAGE_CODE_WRONG);
        }
        CaptchaUtil.clear(request);
    }
}
